<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

/**
 * App\Models\ProductImages
 *
 * @property int $id
 * @property int|null $product_id
 * @property string $thumb
 * @property string $image
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\ProductImages newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\ProductImages newQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\ProductImages query()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\ProductImages whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\ProductImages whereImage($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\ProductImages whereProductId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\ProductImages whereThumb($value)
 * @mixin \Eloquent
 */
class ProductImages extends Model
{
    protected $table = 'product_images';
    protected $primaryKey = 'id';
    protected $guarded    = [];

    public $timestamps = false;

    /**
     * @param $value
     * @return string
     */
    public function getThumbAttribute($value){
        return image_url($value);
    }

    /**
     * @param $value
     */
    public function setThumbAttribute($value){
        $this->attributes['thumb'] = str_replace(material_url(), '', $value);
    }

    /**
     * @param $value
     * @return string
     */
    public function getImageAttribute($value){
        return $value ? material_url($value) : $value;
    }

    /**
     * @param $value
     */
    public function setImageAttribute($value){
        $this->attributes['image'] = str_replace(material_url(), '', $value);
    }
}
